var numberOfMatches = function(n) {
    let winNumber = 0;
    let matchTimes = 0;
    if(n===0){
        return 0;
    }
        do {
            if (n%2===0){
                winNumber = parseInt(n/2)
                matchTimes = matchTimes + parseInt(n/2)
                n = winNumber
            }else{
                winNumber = parseInt((n-1)/2+1)
                matchTimes = matchTimes + parseInt((n-1)/2)
                n = winNumber
            }

        }while (winNumber>1);

    return matchTimes
};

console.log(numberOfMatches(14))